package com.wanmait.schedule.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.schedule.entity.Classroom;
import com.wanmait.schedule.mapper.ClassroomMapper;
import com.wanmait.schedule.service.ClassroomService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 教室表 服务实现类
 * </p>
 *
 * @author wanmait
 * @since 2022-12-05
 */
@Service
public class ClassroomServiceImpl extends ServiceImpl<ClassroomMapper, Classroom> implements ClassroomService {

    @Resource
    private ClassroomMapper classroomMapper;

    @Override
    public List<Classroom> listStudy() {
        LambdaQueryWrapper<Classroom> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Classroom::getClassroomTypeId,2);
        List<Classroom> classrooms = classroomMapper.selectList(queryWrapper);
        return classrooms;
    }

    @Override
    public PageInfo<Classroom> list(Classroom classroom, Integer pageNum) {
        if(pageNum==null){
            pageNum=1;
        }
        PageHelper.startPage(pageNum,5);
        List<Classroom> classrooms = classroomMapper.list(classroom);
        PageInfo<Classroom> pageInfo = new PageInfo<>(classrooms,7);
        return pageInfo;
    }

    @Override
    public Classroom findById(Integer id) {
        return classroomMapper.findById(id);
    }
}
